import { _decorator, Component, Node, Vec3 } from 'cc';
import { eShiohoEvent, shiohoEventManager } from '../event/shiohoEventManager';
import { guideCenter } from '../guide/guideCenter';
import { guideMgr } from '../guide/guideMgr';
import { IGuideTips } from '../guide/iGuide';
import { forcePanel } from './forcePanel';
import { weakPanel } from './weakPanel';
const { ccclass, property } = _decorator;

@ccclass('main')
export class main extends Component {

    @property(weakPanel)
    weakUIPanel: weakPanel;
    @property(forcePanel)
    forcePanel: forcePanel;

    onLoad() {
        guideMgr.Inst;
    }

    start() {
        shiohoEventManager.getInstance().addObserver(eShiohoEvent.SwitchWeakPanel, this.onSwitchWeakPanel.bind(this));
        shiohoEventManager.getInstance().addObserver(eShiohoEvent.UpdateWeakFingerPos, this.onUpdateWeakFingerPos.bind(this));
        shiohoEventManager.getInstance().addObserver(eShiohoEvent.SwitchForcePanel, this.onSwitchForcePanel.bind(this));
        shiohoEventManager.getInstance().addObserver(eShiohoEvent.RefreshForcePanel, this.onRefreshForcePanel.bind(this));
        shiohoEventManager.getInstance().addObserver(eShiohoEvent.RefreshForceTips, this.onRefreshForceTips.bind(this));

        //执行未完成的引导
        guideMgr.Inst.runGuides();

        //直接触发引导1
        guideCenter.triggerGuide(1);

    }

    update(deltaTime: number) {
        guideMgr.Inst.update(deltaTime);
    }

    private onSwitchWeakPanel(args) {
        let isShow = args[0] as boolean;
        this.weakUIPanel.activeSelf(isShow);
    }

    private onUpdateWeakFingerPos(args) {
        let pos = args[0] as Vec3;
        this.weakUIPanel.updateFingerPos(pos);
    }

    private onSwitchForcePanel(args) {
        let isShow = args[0] as boolean;
        this.forcePanel.activeSelf(isShow);
    }

    private onRefreshForcePanel(args) {
        let content = args[0] as any;
        this.forcePanel.refresh(content);
    }

    private onRefreshForceTips(args) {
        let tips = args[0] as IGuideTips;
        this.forcePanel.refreshTips(tips);
    }
}


